<!DOCTYPE html>
<html>
<head>
<include file="Public:header" />
<!-- jqgrid-->
<link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<p>
                    		<button type="button" id="add" class="btn btn-white btn-sm btn-outline"><i class="fa fa-plus-square-o"></i>&nbsp;新增</button>
                    		<button type="button" id="edit" class="btn btn-white btn-sm btn-outline"><i class="fa fa-edit"></i>&nbsp;修改</button>
                    		<button type="button" id="del" class="btn btn-white btn-sm btn-outline"><i class="fa fa-trash-o"></i>&nbsp;删除</button>
                    	</p>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
$(document).ready(function () {
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllData',
    	datatype: "json",
        height: 580,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 15,
        rowList: [10, 15, 30, 50],
        colNames: ['ID', '字段', '值', '内容介绍'],
        colModel: [ {name : 'id',index : 'id'},
                    {name : 'field',index : 'field'},
                    {name : 'value',index : 'value',sortable : false,formatter : function(cellvalue, options, rowObject){
                   	 content = '';
                	 if(rowObject.type == 1) {
                		 content = cellvalue;
                	 }else if(rowObject.type == 2) {
                		 content = '该元素为html代码，请移步前台查看';
                	 }
                	 return content;
            	 }},
                    {name : 'content',index : 'content'}
        		],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc",
    });

 	// 设置按钮
    $("#table_list").jqGrid('navGrid', '#pager_list', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    });
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
    
  	//增
	$("#add").click(function() {
		layerDialog("添加",'__URL__/add',"90%","350px",true);
	})
	
    //改
    $("#edit").click(function() {
    	var id = $("#table_list").jqGrid('getGridParam','selrow');
    	if(id != null) {
    		layerDialog("修改",'__URL__/edit?id='+id,"90%","710px",true);
    	}else {
    		layer.msg("您没有选取数据！");
    	}
    })
    
    //删
    $("#del").click(function() {
    	var id = $("#table_list").jqGrid('getGridParam','selrow');
    	if(id == 9 || id == 10 || id == 11){
    		layer.msg("网页重要组成部分，无法删除！");
    		return false;
    	}
    	if(id != null) {
    		layer.confirm('确定执行？', function(index){
        		$.ajax({
        			url:"__URL__/logicDel",
        			type:"post",
        			data:{'id':id},
        			success:function(json){
        				var data = eval("("+json+")");
        				if(data.status == 1){
        					layer.msg(data.info);
        					$('#table_list').trigger("reloadGrid");
        				}else{
        					layer.msg(data.info);
        				}
        			}
        		})
        	    layer.close(index);
        	});
    	}else {
    		layer.msg("您没有选取数据！");
    	}
    })
});
</script>
</html>